home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / all macintosh / quicktime for java / playmovie / src / filemenu.java next >
Encoding:
Java Source  |  2000-06-23  |  3.9 KB  |  136 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.applet.*;
  11. import java.io.IOException;
  12.  
  13.  
  14. import quicktime.*;
  15. import quicktime.io.*;
  16. import quicktime.std.*;
  17. import quicktime.std.movies.*;
  18. import quicktime.app.players.*;
  19. import quicktime.app.display.*;
  20.  
  21.  
  22. public class FileMenu {
  23.     PlayMovie myPlayMovie;
  24.         
  25.     public FileMenu (PlayMovie src) {
  26.         this.myPlayMovie = src;
  27.         
  28.         // make the menu bar up
  29.         MenuBar menuBar = new MenuBar();
  30.         Menu fileMenu = new Menu ("File");
  31.         
  32.         MenuItem openMenuItem = new MenuItem ("Open...");
  33.         MenuItem openURLMenuItem = new MenuItem("Open URL...");
  34.         MenuItem presentMovieMenuItem = new MenuItem ("Present Movie");
  35.         MenuItem quitMenuItem = new MenuItem("Quit");
  36.         
  37.         fileMenu.add(openMenuItem);
  38.         fileMenu.add(openURLMenuItem);
  39.         fileMenu.addSeparator();
  40.         fileMenu.add(presentMovieMenuItem);
  41.         fileMenu.addSeparator();
  42.         fileMenu.add(quitMenuItem);
  43.             
  44.         menuBar.add (fileMenu);
  45.         myPlayMovie.setMenuBar (menuBar);
  46.                     
  47.         openURLMenuItem.addActionListener (new ActionListener () {
  48.             public void actionPerformed(ActionEvent event) {
  49.                 myPlayMovie.stopPlayer();
  50.                 
  51.                 // this will set the new movie in its action method if OK is chosen
  52.                 Open_URL d = new Open_URL (myPlayMovie);
  53.                 d.pack();
  54.                 d.show();
  55.              }
  56.         });
  57.         openMenuItem.addActionListener (new ActionListener () {
  58.             public void actionPerformed(ActionEvent event) {
  59.                 myPlayMovie.stopPlayer();
  60.                     
  61.                     // creat a movie through the file-open dialog of QT
  62.                 try {
  63.                     QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);
  64.                     myPlayMovie.createNewMovieFromURL ("file://" + qtf.getPath());
  65.                 } catch (QTException e) {
  66.                     if (e.errorCode() != Errors.userCanceledErr)
  67.                          e.printStackTrace();
  68.                  }
  69.              }
  70.         });
  71.         quitMenuItem.addActionListener (new ActionListener () {
  72.             public void actionPerformed(ActionEvent event) {
  73.                     // closes down QT and quits
  74.                 PlayMovie.goAway();
  75.              }
  76.         });
  77.         presentMovieMenuItem.addActionListener (new ActionListener () {
  78.             public void actionPerformed(ActionEvent event) {
  79.                 try {                    
  80.                     if (myPlayMovie.getPlayer() == null) return;
  81.                     
  82.                     // present in full screen mode
  83.                     // use the current screen resolution and current movie
  84.                     FullScreenWindow w = new FullScreenWindow(new FullScreen(), myPlayMovie);
  85.                     MoviePlayer mp = new MoviePlayer (myPlayMovie.getMovie());
  86.                     QTCanvas c = new QTCanvas (QTCanvas.kPerformanceResize, 0.5F, 0.5F);
  87.                     w.add (c);
  88.                     w.setBackground (Color.black);
  89.                     
  90.                         //remove the movie from its current QTCanvas 
  91.                     myPlayMovie.getCanvas().removeClient();
  92.                         //put it into the new canvas of the FullScreenWindow
  93.                         //we restore this in the HideFSWindow's action
  94.                     c.setClient (mp, false);
  95.                     
  96.                         // show FSWindow and setup hide - it is invoke through a mousePressed action
  97.                         // so we set this as a listener for both the window and the canvas
  98.                     w.show();
  99.                     HideFSWindow hw = new HideFSWindow (w, myPlayMovie, c);
  100.                     w.addMouseListener (hw);                            
  101.                     c.addMouseListener (hw);                            
  102.                     
  103.                         // start the movie playing
  104.                     mp.setRate (1);
  105.                 } catch (QTException err) {
  106.                     err.printStackTrace();
  107.                 }
  108.             }
  109.         });            
  110.     }
  111.     
  112.     static class HideFSWindow extends MouseAdapter {
  113.         HideFSWindow (FullScreenWindow w, PlayMovie pm, QTCanvas c) {
  114.             this.w = w;
  115.             this.pm = pm;
  116.             this.c = c;
  117.         }
  118.         
  119.         private FullScreenWindow w;
  120.         private PlayMovie pm;
  121.         private QTCanvas c;
  122.         
  123.         public void mousePressed (MouseEvent me) {
  124.             try {
  125.                     // this will stop the movie and reset it back to the previous window
  126.                 c.removeClient();
  127.                 pm.getCanvas().setClient (pm.getPlayer(), false);
  128.             } catch (QTException e) {
  129.                 e.printStackTrace();
  130.             } finally {
  131.                 w.hide();
  132.             }
  133.         }
  134.     }
  135. }            
  136.